//
//  FDProvinceViewController.m
//  FamousDoctorOnline
//
//  Created by 应谨鸿 on 16/7/6.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDProvinceViewController.h"
#import "FDProvinceModel.h"
#import "FDCityViewController.h"
#import "FDWeatherView.h"

@interface FDProvinceViewController ()

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation FDProvinceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择当前省份位置";
    
    self.view.backgroundColor = WHITE_COLOR;
    
    //设置导航栏上面的字体颜色
    [self.navigationController.navigationBar setTintColor:WHITE_COLOR];
    
    //设定统一的导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:kThemeColor];
    
    //统一设定导航控制器左边的item的样式
    [self setupLeftNavBarButtonItem];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifier = @"cell2";
    
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];}
    
    FDProvinceModel *cityModel = self.dataArray[indexPath.row];
    
    cell.textLabel.text = cityModel.name;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

/**
 *  cell点击
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FDCityViewController *cityVC = [[FDCityViewController alloc]init];
    
    FDProvinceModel *model = self.dataArray[indexPath.row];
    
    cityVC.dataArray = model.cities;
    
    [self.navigationController pushViewController:cityVC animated:YES];
    
}

/**
 *  懒加载
 */
- (NSArray *)dataArray{
    
    if (!_dataArray) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"province.plist" ofType:nil];
        
        NSArray *tempArray = [NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray *mArray = [NSMutableArray array];
        
        for (NSDictionary *dict in tempArray) {
            FDProvinceModel *model = [FDProvinceModel provinceModelWithDict:dict];
            
            [mArray addObject:model];
        }
        
        _dataArray = mArray;
    }
    
    return _dataArray;
}

/**
 *  导航栏设置
 */
- (void)setupLeftNavBarButtonItem{
    
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"JianTou"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    
    self.navigationItem.leftBarButtonItem = item;
    
}

/**
 *  pop返回
 */
- (void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
